/**
 * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com)
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.afterturn.easypoi.util;

/**
 * EASYPOI 的公共基础类
 *
 * @author JueYue
 * 2015年4月5日 上午12:59:22
 */
public final class PoiUtil {

    /**
     * @param photoByte
     * @return
     */
    public static String getFileExtendName(byte[] photoByte) {
        String strFileExtendName = "JPG";
        if (photoByte.length == 0) {
            return strFileExtendName;
        }
        try {
            if ((photoByte[0] == 71) && (photoByte[1] == 73) && (photoByte[2] == 70)
                    && (photoByte[3] == 56) && ((photoByte[4] == 55) || (photoByte[4] == 57))
                    && (photoByte[5] == 97)) {
                strFileExtendName = "GIF";
            } else if ((photoByte[6] == 74) && (photoByte[7] == 70) && (photoByte[8] == 73)
                    && (photoByte[9] == 70)) {
                strFileExtendName = "JPG";
            } else if ((photoByte[0] == 66) && (photoByte[1] == 77)) {
                strFileExtendName = "BMP";
            } else if ((photoByte[1] == 80) && (photoByte[2] == 78) && (photoByte[3] == 71)) {
                strFileExtendName = "PNG";
            }
        }catch (Exception e){
            e.printStackTrace();
        }


        return strFileExtendName;
    }
}
